﻿using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;

namespace breakoutsharp.visual.menu
{
    public class DxButton : IScreenObject, IDisposable
    {
        protected Device device = null;
        protected DxSprite selectedSprite = null;
        protected DxSprite notSelectedSprite = null;
        protected Sprite sprite = null;
        protected Microsoft.DirectX.Direct3D.Font font;
        protected bool selected;
        protected SizeF size;
        protected PointF location;
        protected bool visible = true;
        protected Color color;
        protected string text;
        protected bool disposed = false;

        public DxButton(Device dev, Sprite s, Microsoft.DirectX.Direct3D.Font f)
        {
            device = dev;
            sprite = s;
            font = f;

            selectedSprite = new DxSprite(dev, @"\gfx\", "btn1", new Size(197, 37), Color.FromArgb(255, 255, 0, 255));
            notSelectedSprite= new DxSprite(dev, @"\gfx\", "btn2", new Size(150,37), Color.FromArgb(255,255,0,255));

        }

        public void Draw()
        {
            if (this.selected)
            {
                selectedSprite.Draw(sprite, new Rectangle(), new Point((int)location.X, (int)location.Y), size);
            }
            else
            {
                notSelectedSprite.Draw(sprite, new Rectangle(), new Point((int)location.X, (int)location.Y), size);
            }

            font.DrawText(null, text, (int)location.X + 30, (int)location.Y + 10, color);
        }

        #region IScreenObject Members

        public void Draw(Device dev)
        {

        }

        public PointF Location
        {
            get
            {
                return location;
            }
            set
            {
                location = value;
            }
        }

        public SizeF Size
        {
            get
            {
                return size;
            }
            set
            {
                size = value;
            }
        }

        public bool Visible
        {
            get
            {
                return visible;
            }
            set
            {
                visible = value;
            }
        }

        public Rectangle GetRect
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public RectangleF GetRectF
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        public Microsoft.DirectX.Direct3D.Font Font
        {
            get
            {
                return font;
            }
        }

        public bool Selected
        {
            get
            {
                return selected;
            }
            set
            {
                selected = value;
            }
        }

        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
            }
        }

        public Color TextColor
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
            }
        }

        #region IDisposable Members

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        public void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    if (!(device == null))
                    {
                        if (font != null)
                            font.Dispose();
                        if (selectedSprite != null)
                            selectedSprite.Dispose();
                        if (notSelectedSprite != null)
                            notSelectedSprite.Dispose();
                        if (sprite != null)
                            sprite.Dispose();

                        device = null;
                    }

                }
                disposed = true;
            }
        }

        #endregion
    }
}
